home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kdatepicker.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  6.9 KB  |  258 lines

  1. /*  -*- C++ -*-
  2.     This file is part of the KDE libraries
  3.     Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
  4.               (C) 1998-2001 Mirko Boehm (mirko@kde.org)
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef KDATEPICKER_H
  21. #define KDATEPICKER_H
  22. #include <qdatetime.h>
  23. #include <qframe.h>
  24. #include <kdelibs_export.h>
  25.  
  26. class QLineEdit;
  27. class QToolButton;
  28. class KDateValidator;
  29. class KDateTable;
  30.  
  31. /**
  32.  * @short A date selection widget.
  33.  *
  34.  * Provides a widget for calendar date input.
  35.  *
  36.  *     Different from the
  37.  *     previous versions, it now emits two types of signals, either
  38.  * dateSelected() or dateEntered() (see documentation for both
  39.  *     signals).
  40.  *
  41.  *     A line edit has been added in the newer versions to allow the user
  42.  *     to select a date directly by entering numbers like 19990101
  43.  *     or 990101.
  44.  *
  45.  * \image html kdatepicker.png "KDE Date Widget"
  46.  *
  47.  *     @version $Id: kdatepicker.h 669008 2007-05-28 10:32:33Z mueller $
  48.  *     @author Tim Gilman, Mirko Boehm
  49.  *
  50.  **/
  51. class KDEUI_EXPORT KDatePicker: public QFrame
  52. {
  53.   Q_OBJECT
  54.   Q_PROPERTY( QDate date READ date WRITE setDate)
  55.   Q_PROPERTY( bool closeButton READ hasCloseButton WRITE setCloseButton )
  56.   Q_PROPERTY( int fontSize READ fontSize WRITE setFontSize )
  57.  
  58. public:
  59.   /** The usual constructor.  The given date will be displayed
  60.    * initially.
  61.    **/
  62.   KDatePicker(QWidget *parent=0,
  63.           QDate=QDate::currentDate(),
  64.           const char *name=0);
  65.  
  66.   /** The usual constructor.  The given date will be displayed
  67.    * initially.
  68.    * @since 3.1
  69.    **/
  70.   KDatePicker(QWidget *parent,
  71.           QDate,
  72.           const char *name,
  73.           WFlags f); // ### KDE 4.0: Merge
  74.  
  75.   /**
  76.    * Standard qt widget constructor. The initial date will be the
  77.    * current date.
  78.    * @since 3.1
  79.    */
  80.   KDatePicker( QWidget *parent, const char *name );
  81.  
  82.   /**
  83.    * The destructor.
  84.    **/
  85.   virtual ~KDatePicker();
  86.  
  87.   /** The size hint for date pickers. The size hint recommends the
  88.    *   minimum size of the widget so that all elements may be placed
  89.    *  without clipping. This sometimes looks ugly, so when using the
  90.    *  size hint, try adding 28 to each of the reported numbers of
  91.    *  pixels.
  92.    **/
  93.   QSize sizeHint() const;
  94.  
  95.   /**
  96.    * Sets the date.
  97.    *
  98.    *  @returns @p false and does not change anything
  99.    *      if the date given is invalid.
  100.    **/
  101.   bool setDate(const QDate&);
  102.  
  103.   /**
  104.    * Returns the selected date.
  105.    * @deprecated
  106.    **/
  107.   const QDate& getDate() const KDE_DEPRECATED;
  108.  
  109.   /**
  110.    * @returns the selected date.
  111.    */
  112.   const QDate &date() const;
  113.  
  114.   /**
  115.    * Enables or disables the widget.
  116.    **/
  117.   void setEnabled(bool);
  118.  
  119.   /**
  120.    * @returns the KDateTable widget child of this KDatePicker
  121.    * widget.
  122.    * @since 3.2
  123.    */
  124.   KDateTable *dateTable() const { return table; }
  125.  
  126.   /**
  127.    * Sets the font size of the widgets elements.
  128.    **/
  129.   void setFontSize(int);
  130.   /**
  131.    * Returns the font size of the widget elements.
  132.    */
  133.   int fontSize() const
  134.     { return fontsize; }
  135.  
  136.   /**
  137.    * By calling this method with @p enable = true, KDatePicker will show
  138.    * a little close-button in the upper button-row. Clicking the
  139.    * close-button will cause the KDatePicker's topLevelWidget()'s close()
  140.    * method being called. This is mostly useful for toplevel datepickers
  141.    * without a window manager decoration.
  142.    * @see hasCloseButton
  143.    * @since 3.1
  144.    */
  145.   void setCloseButton( bool enable );
  146.  
  147.   /**
  148.    * @returns true if a KDatePicker shows a close-button.
  149.    * @see setCloseButton
  150.    * @since 3.1
  151.    */
  152.   bool hasCloseButton() const;
  153.  
  154. protected:
  155.   /// to catch move keyEvents when QLineEdit has keyFocus
  156.   virtual bool eventFilter(QObject *o, QEvent *e );
  157.   /// the resize event
  158.   virtual void resizeEvent(QResizeEvent*);
  159.   /// the year forward button
  160.   QToolButton *yearForward;
  161.   /// the year backward button
  162.   QToolButton *yearBackward;
  163.   /// the month forward button
  164.   QToolButton *monthForward;
  165.   /// the month backward button
  166.   QToolButton *monthBackward;
  167.   /// the button for selecting the month directly
  168.   QToolButton *selectMonth;
  169.   /// the button for selecting the year directly
  170.   QToolButton *selectYear;
  171.   /// the line edit to enter the date directly
  172.   QLineEdit *line;
  173.   /// the validator for the line edit:
  174.   KDateValidator *val;
  175.   /// the date table
  176.   KDateTable *table;
  177.   /// the size calculated during resize events
  178.     //  QSize sizehint;
  179.   /// the widest month string in pixels:
  180.   QSize maxMonthRect;
  181. protected slots:
  182.   void dateChangedSlot(QDate);
  183.   void tableClickedSlot();
  184.   void monthForwardClicked();
  185.   void monthBackwardClicked();
  186.   void yearForwardClicked();
  187.   void yearBackwardClicked();
  188.   /**
  189.    * @since 3.1
  190.    * @deprecated in 3.2
  191.    */
  192.   void selectWeekClicked();
  193.   /**
  194.    * @since 3.1
  195.    */
  196.   void selectMonthClicked();
  197.   /**
  198.    * @since 3.1
  199.    */
  200.   void selectYearClicked();
  201.   /**
  202.    * @since 3.1
  203.    */
  204.   void lineEnterPressed();
  205.   /**
  206.    * @since 3.2
  207.    */
  208.   void todayButtonClicked();
  209.   /**
  210.    * @since 3.2
  211.    */
  212.   void weekSelected(int);
  213.  
  214. signals:
  215.   // ### KDE 4.0 Make all QDate parameters const references
  216.  
  217.   /** This signal is emitted each time the selected date is changed.
  218.    *  Usually, this does not mean that the date has been entered,
  219.    *  since the date also changes, for example, when another month is
  220.    *  selected.
  221.    *  @see dateSelected
  222.    */
  223.   void dateChanged(QDate);
  224.   /** This signal is emitted each time a day has been selected by
  225.    *  clicking on the table (hitting a day in the current month). It
  226.    *  has the same meaning as dateSelected() in older versions of
  227.    *  KDatePicker.
  228.    */
  229.   void dateSelected(QDate);
  230.   /** This signal is emitted when enter is pressed and a VALID date
  231.    *  has been entered before into the line edit. Connect to both
  232.    *  dateEntered() and dateSelected() to receive all events where the
  233.    *  user really enters a date.
  234.    */
  235.   void dateEntered(QDate);
  236.   /** This signal is emitted when the day has been selected by
  237.    *  clicking on it in the table.
  238.    */
  239.   void tableClicked();
  240.  
  241. private slots:
  242.   void ensureSelectYearIsUp();
  243.  
  244. private:
  245.   /// the font size for the widget
  246.   int fontsize;
  247.  
  248. protected:
  249.   virtual void virtual_hook( int id, void* data );
  250. private:
  251.   void init( const QDate &dt );
  252.   void fillWeeksCombo(const QDate &date);
  253.   class KDatePickerPrivate;
  254.   KDatePickerPrivate *d;
  255. };
  256.  
  257. #endif //  KDATEPICKER_H
  258.